﻿
@{
    ViewBag.Title = "Item";
}

<style>
    .mainDiv {
        padding: 10px 10px 10px 10px;
    }

    .col-xs-6 {
        padding: 0;
    }
    /*基本表单提交样式*/
    .lr-form-wrap {
        position: relative;
        width: 100%;
        height: 100%;
        padding: 15px 30px 0px 0px;
    }

    .lr-form-item {
        position: relative;
        min-height: 38px;
        padding: 5px 0px 5px 100px;
    }

    .lr-form-item-title {
        position: absolute;
        top: 0;
        left: 0;
        width: 100px;
        height: 100%;
        line-height: 38px;
        text-align: right;
        padding-right: 10px;
    }

        .lr-form-item-title > font {
            position: absolute;
            top: 0;
            right: 2px;
            color: red;
        }

    .lr-input-button {
        position: absolute;
        right: 0;
        top: 0;
        width: 16px;
        height: 100%;
        line-height: 28px;
        cursor: pointer;
        overflow: hidden;
        z-index: 10;
    }

    .lr-form-item-btn {
        position: absolute;
        top: 4px;
        right: 0;
        padding: 4px 8px;
    }
</style>
<div class="mainDiv">
    <div class="lr-form-wrap" id="form">
        <div class="col-xs-6 lr-form-item">
            <div class="lr-form-item-title">名字<font face="宋体">*</font></div>
            <input id="MemberName" type="text" class="form-control" />
        </div>
        <div class="col-xs-6 lr-form-item" style="width:200px;">
            <div class="lr-form-item-title">性别<font face="宋体">*</font></div>
            <select id="sltSex">
                <option value='M'>男</option>
                <option value='F'>女</option>
            </select>
        </div>
        <div class="col-xs-6 lr-form-item" style="width:200px;">
            <div class="lr-form-item-title">关系<font face="宋体">*</font></div>
            <select id="sltRelationName">
                <option value='子'>子</option>
                <option value='女'>女</option>
                <option value='养子'>养子</option>
                <option value='养女'>养女</option>
                <option value='配偶'>配偶</option>
                <option value='配偶1'>配偶1</option>
                <option value='配偶2'>配偶2</option>
            </select>
        </div>
        <div class="col-xs-6 lr-form-item" style="height:2px;"> </div>
        <div class="col-xs-6 lr-form-item">
            <div class="lr-form-item-title">出生日期<font face="宋体">*</font></div>
            <input id="Birthday" type="text" class="form-control" />
        </div>

        <div class="col-xs-6 lr-form-item">
            <div class="lr-form-item-title">卒于<font face="宋体">*</font></div>
            <input id="DieTime" type="text" class="form-control" />
        </div>

        <div class="col-xs-6 lr-form-item">
            <div class="lr-form-item-title">排行<font face="宋体">*</font></div>
            <input id="Ranking" type="text" class="form-control" />
        </div>

        <div class="col-xs-6 lr-form-item">
            <div class="lr-form-item-title">第几代<font face="宋体">*</font></div>
            <input id="GenerationNum" type="text" class="form-control" />
        </div>
        <div class="col-xs-6 lr-form-item">
            <div class="lr-form-item-title">字辈<font face="宋体">*</font></div>
            <input id="GenerationName" type="text" class="form-control" />
        </div>

        <div class="col-xs-6 lr-form-item">
            <div class="lr-form-item-title">简介<font face="宋体">*</font></div>
            <textarea id="Profile" rows="2" cols="20" class="form-control" ></textarea>
        </div>

        <div class="col-xs-6 lr-form-item" style="height:2px;"> </div>
        <div class="col-xs-6 lr-form-item">
            <input id="btnSave" type="button" value="保存" class="btn btn-default" />
        </div>
    </div>

</div>

<input id="ParentId" type="hidden" /> 
<input id="FamilyInfoId" type="hidden" value="@ViewBag.Member.FamilyInfoId" />
<input id="MemberId" type="hidden" value="@ViewBag.Member.MemberId" />
<script type="text/javascript">
    var fid = '@ViewBag.FId';
    var type = '@ViewBag.Type';
    if (type == 'e') {
        $('#sltRelationName').val('@ViewBag.Member.RelationName');
        $('#sltSex').val('@ViewBag.Member.Sex');

        $('#MemberName').val('@ViewBag.Member.MemberName');
        $('#Birthday').val('@ViewBag.Member.Birthday');
        $('#DieTime').val('@ViewBag.Member.DieTime');
        $('#Ranking').val('@ViewBag.Member.Ranking');
        $('#GenerationNum').val('@ViewBag.Member.GenerationNum');
        $('#GenerationName').val('@ViewBag.Member.GenerationName');
        $('#Profile').val('@ViewBag.Member.Profile');
        $('#ParentId').val('@ViewBag.Member.ParentId');
    } else {
        $('#MemberId').val(0);
        $('#ParentId').val('@ViewBag.Member.MemberId');
        $('#FamilyInfoId').val('@ViewBag.Member.FamilyInfoId');
        if ('0' == '@ViewBag.Member.FamilyInfoId') {
            $('#FamilyInfoId').val(fid);
        }
    }

    $('#btnSave').on("click", function () {
        //alert($('#sltSex').val() + $('#sltRelationName').val());
        var jsonData = { "MemberId": 0, "MemberName": "", "Sex": "", "Birthday": "", "FamilyInfoId": 0, "Ranking": 0, "PicUrl": "", "Profile": "", "DieTime": "", "IsDelete": 0, "ParentId": 0, "Remarks": "", "GenerationNum": 0, "GenerationName": "", "RelationName": "" };

        jsonData.MemberName = $('#MemberName').val();
        jsonData.Birthday = $('#Birthday').val();
        jsonData.DieTime = $('#DieTime').val();
        jsonData.Ranking = $('#Ranking').val();
        jsonData.GenerationNum = $('#GenerationNum').val();
        jsonData.GenerationName = $('#GenerationName').val();
        jsonData.RelationName = $('#sltRelationName').val();
        jsonData.Sex = $('#sltSex').val();
        jsonData.ParentId = $('#ParentId').val();
        jsonData.Profile = $('#Profile').val();
        jsonData.FamilyInfoId = $('#FamilyInfoId').val();

        var url = '';
        if (type == 'e') {
            jsonData.MemberId = $('#MemberId').val();
            url = '@Url.Action("Edit", "FamilyInfo")';
        }
        else {
            //jsonData.ParentId = $('#ParentId').val();
            url = '@Url.Action("Save", "FamilyInfo")';
        }

            $.post(url, jsonData, function (response) {
                // 请求成功时的回调函数
                var result = JSON.stringify(response);
                if (result == '1') {
                    url ='@Url.Action("index2", "FamilyInfo")';
                    window.location.href = url + '?edit=9&fid=' + $('#FamilyInfoId').val();
                } else {
                    alert('保存失败');
                }
            }, 'json');

    });
</script>

